Skip to content

perf: extend_fallback optimization - #567

Merged
alejandro-vaz merged 3 commits into
servo:v2from
fereidani:v2_extend_fallback
Sep 3, 2026
Merged

perf: extend_fallback optimization#567
alejandro-vaz merged 3 commits into
servo:v2from
fereidani:v2_extend_fallback

Conversation

@fereidani

Copy link
Copy Markdown
Contributor

This optimizes extend_fallback with some unsafe code. I tried to document the unsafe behavior as much as possible to avoid future mistakes.

Benchmark results:

bench_extend            time:   [34.645 ns 34.823 ns 34.999 ns]
                        change: [−74.574% −74.269% −74.003%] (p = 0.00 < 0.05)
                        Performance has improved.

bench_extend_small      time:   [20.678 ns 20.851 ns 21.036 ns]
                        change: [−44.092% −42.884% −41.620%] (p = 0.00 < 0.05)
                        Performance has improved.

bench_extend_filtered   time:   [117.77 ns 118.27 ns 118.79 ns]
                        change: [−32.519% −32.049% −31.581%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) low mild
  2 (2.00%) high mild

bench_extend_filtered_small
                        time:   [22.823 ns 23.030 ns 23.247 ns]
                        change: [−35.161% −33.879% −32.470%] (p = 0.00 < 0.05)
                        Performance has improved.

bench_extend_from_slice time:   [36.363 ns 36.499 ns 36.644 ns]
                        change: [−74.015% −73.725% −73.444%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high severe

bench_extend_from_slice_small
                        time:   [20.650 ns 20.784 ns 20.940 ns]
                        change: [−43.591% −42.283% −40.916%] (p = 0.00 < 0.05)
                        Performance has improved.

bench_extend_vec        time:   [60.429 ns 60.616 ns 60.839 ns]
                        change: [−10.449% −9.9262% −9.3862%] (p = 0.00 < 0.05)
                        Performance has improved.

bench_extend_vec_small  time:   [18.259 ns 18.324 ns 18.391 ns]
                        change: [+0.2642% +0.9616% +1.6561%] (p = 0.01 < 0.05)
                        Change within noise threshold.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high severe

bench_extend_vec_filtered
                        time:   [150.21 ns 150.63 ns 151.08 ns]
                        change: [+5.9960% +6.5508% +7.0910%] (p = 0.00 < 0.05)
                        Performance has regressed.

bench_extend_vec_filtered_small
                        time:   [18.556 ns 18.663 ns 18.779 ns]
                        change: [−3.2075% −2.4870% −1.8235%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

bench_extend_from_slice_vec
                        time:   [62.906 ns 63.110 ns 63.350 ns]
                        change: [−1.0367% −0.5490% −0.0662%] (p = 0.03 < 0.05)
                        Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

bench_extend_from_slice_vec_small
                        time:   [18.380 ns 18.463 ns 18.569 ns]
                        change: [+3.8765% +6.5163% +9.4532%] (p = 0.00 < 0.05)
                        Performance has regressed.

@alejandro-vaz

alejandro-vaz commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

oh yeah this brings it to the v1 performance baseline

it's similar to what I did in #405

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

I have stopped optimizing for performance really, the codebase is so bloated, we need to first restructure it

@alejandro-vaz alejandro-vaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terrible for the codebase, good for performance

@fereidani

Copy link
Copy Markdown
Contributor Author

It is my last perf related contribution hopefully 😂, I'll switch to refactoring. I promise(pinky).

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

I'm not sure how we are going to approach simplifying the codebase

I just tried to make the TaggedLen change about storing the on_heap bit on MSB, and it yielded solid -10% on push, but then a random filtered bench gave +70% for no good reason

@fereidani

Copy link
Copy Markdown
Contributor Author

I'll do the trusted len now, for the cold reserve give me few days to think about it in background.

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

oh are we missing trustedlen implementations??

@fereidani

Copy link
Copy Markdown
Contributor Author

I'm sorry that was a brain hiccup, this happens when you do to many PRs 😂, I meant TaggedLen, I have another TrustedLen PR for rust itself word jumped out in the wrong place.

@fereidani

Copy link
Copy Markdown
Contributor Author

Btw TrustedLen is nightly and we don't need to support it.

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

yeah I spent too much time on nightly that TrustedLen was normal for me

@alejandro-vaz
alejandro-vaz added this pull request to the merge queue Sep 3, 2026
Merged via the queue into servo:v2 with commit 3f69f79 Sep 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants